<%-- 
    Document   : response
    Created on : 18-ene-2009, 20:53:47
    Author     : germinus
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<sql:query var="medicine_events" dataSource="jdbc/cardeacontrol">
    SELECT m.id,m.tagId ,mt.mName ,lo.lName ,me.date ,met.meName
    FROM medicine_events as me, medicines as m, medicine_events_type
    as met, localization as lo, medicine_types mt
    WHERE me.medicineId = m.id
    AND me.typeEventId=met.id
    AND m.typeId=mt.id
    AND m.localizationId=lo.id
    <c:if test="${param.type_id != 0}">
        AND m.typeId = ? <sql:param value="${param.type_id}"/>
    </c:if>
    <c:if test="${param.loc_id != 0}">
        AND m.localizationId  = ? <sql:param value="${param.loc_id}"/>
    </c:if>
    <c:if test="${param.type_event != 0}">
        AND me.typeEventid = ? <sql:param value="${param.type_event}"/>
    </c:if>
    <c:if test="${param.code != ''}">
        AND m.tagId = ? <sql:param value="${param.code}"/>
    </c:if>
    <c:if test="${(!empty param.fromDate) && (!empty param.toDate)}">
        AND me.date between ? <sql:param value="${param.fromDate}"/> and ? <sql:param value="${param.toDate}"/>
    </c:if>
    order by date desc
    <%-- LIMIT ${(param.page-1)*3},${param.page*3} --%>
</sql:query>

<c:choose>
    <c:when test="${medicine_events.rowCount == 0}">
        <table id="event_results">
            <tr><td>No hay resultados</td></tr>
        </table>
    </c:when>
    <c:otherwise>
        <table id="event_results"  width=100%>
            <thead>
                <tr>
                    <th sort="fecha">Fecha</th>
                    <th sort="evento">Evento</th>
                    <th sort="medicamento">Medicamento</th>
                    <th sort="codigo">C&oacute;digo</th>
                    <th sort="localizacion">Localizaci&oacute;n</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach var="medicine_event" items="${medicine_events.rows}">
                    <tr onclick="showDetails(${medicine_event.id});">
                        <td>${medicine_event.date}</td>
                        <td>${medicine_event.meName}</td>
                        <td>${medicine_event.mName}</td>
                        <td>${medicine_event.tagId}</td>
                        <td>${medicine_event.lName}</td>
                    </tr>
                </c:forEach>
            </tbody>
            <tfoot>
                <tr>
                    <td colspan=5>
                        <div class="pagination"></div>
                        <div class="paginationTitle">P&aacute;gina</div>

                        <div class="selectPerPage"></div>
                        <div class="status"></div>
                    </td>
                </tr>
            </tfoot>

        </table>
    </c:otherwise>
</c:choose>



